USE [CallCenter]
GO

/****** Object:  UserDefinedFunction [dbo].[GetActivity]    Script Date: 07/31/2013 23:04:04 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date, ,>
-- Description:	<Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[GetActivity] 
(
	@visitDate varchar(10),
	@fecha varchar(10),
	@today DATETIME 
)
RETURNS varchar(10)
AS
BEGIN
	DECLARE @Activity varchar(10)
	IF(@visitDate IS NULL)
		SET @Activity = 'Call'
	ELSE
		IF(@fecha IS NULL)
			SET @Activity = 'Visit'
		ELSE
			IF(@fecha >= CONVERT(VARCHAR(10),@today,101) AND @fecha < @visitDate)
				SET @Activity = 'Call'
			ELSE
				SET @Activity = 'Visit'
	-- Return the result of the function
	RETURN @Activity

END

GO

